public class Test {

    //合并两个有序列表
    public static SingleLinkedList.ListNode mergeTwoList(SingleLinkedList.ListNode head1,
                                                  SingleLinkedList.ListNode head2) {
        SingleLinkedList.ListNode newH = new SingleLinkedList.ListNode(-1);
        SingleLinkedList.ListNode tmpH = newH;
        while (head1 != null && head2 != null) {
            if (head1.val < head2.val) {
                tmpH.next = head1;
                head1 = head1.next;
            }else {
                tmpH.next = head2;
                head2 = head2.next;
            }
            tmpH = tmpH.next;
        }

        if (head1 != null) {
            tmpH.next = head1;
        }

        if (head2 != null) {
            tmpH.next = head2;
        }

        return newH.next;
    }

    public static void main2(String[] args) {
        SingleLinkedList singleLinkedList = new SingleLinkedList();

        singleLinkedList.addLast(11);
        singleLinkedList.addLast(13);
        singleLinkedList.addLast(14);
        singleLinkedList.addLast(15);
        singleLinkedList.addLast(16);

        singleLinkedList.display();

        SingleLinkedList singleLinkedList2 = new SingleLinkedList();

        singleLinkedList2.addLast(11);
        singleLinkedList2.addLast(13);
        singleLinkedList2.addLast(77);
        singleLinkedList2.addLast(78);
        singleLinkedList2.addLast(99);

        singleLinkedList2.display();
        System.out.println("===================");
        SingleLinkedList.ListNode head =  mergeTwoList(singleLinkedList2.head,singleLinkedList.head);
        singleLinkedList.display(head);
    }

    public static void main(String[] args) {
        SingleLinkedList singleLinkedList = new SingleLinkedList();

        singleLinkedList.addLast(12);
        singleLinkedList.addLast(13);
        singleLinkedList.addLast(14);
        singleLinkedList.addLast(15);
        singleLinkedList.addLast(16);

        singleLinkedList.display();
        System.out.println("===============");
        SingleLinkedList.ListNode ret = singleLinkedList.reverseList();
        singleLinkedList.display(ret);
        System.out.println("===============");
        SingleLinkedList.ListNode ret2 = singleLinkedList.findKthToTail(2);
        singleLinkedList.display(ret2);
    }
}
